import pymongo

con = pymongo.MongoClient()

# for db in con.list_databases():
# 	print(db)

con.drop_database("test_db")

# 构建数据库实例
db = con.get_database("test_db")
print(db)

db.drop_collection("test_c1")

# 构建集合实例
collection = db.get_collection("test_c1")
print(collection)


# 插入文档
# r = collection.insert_one({
# 	"name": "qiku"
# })
# print(r)

# rs = collection.insert_many([
# 	{"name": "a0", "age": 10},
# 	{"name": "a1"},
# 	{"name": "a2", "address": "东三街"},
# 	{"name": "a3", "infos": [
# 		{"id": 101, "name": "i1"},
# 		{"id": 102, "name": "i2"},
# 		{"id": 103, "name": "i3"}
#
# 	]},
#
# ])
# print(rs)




# 获取所有的文档
# documents = collection.find({"name": "a0", "age": 10})
# for d in documents:
# 	print(f"文档", d)

# d = collection.find_one({"name": "a0"})
# print(f"文档....", d)


#
# r = collection.update_one({"name": "a0"}, {"$set": {"address": "黄河路"}})
# print(r)

# rs = collection.update_many({"name": "a0"}, {"$set": {"info": "开饭了"}})
# print(rs)

# r = collection.delete_one({"name": "qiku"})
# print(r)

# r = collection.delete_many({"name": "a2"})
# print(r)

con.close()